#include "xmlrpcclient.h"
#include "xmlrpcconv.h"

XmlRpcClient::XmlRpcClient( const QString &host, const QString path, const quint16 port )
: HttpClient( host, port, path, /*"/xmlrpc.php"*/ HttpClient::POST )
{
}


void XmlRpcClient::execute( const QString &method, const QVariantList &params )
{
	m_method = method;
	setPostData( toXmlRpcRequest( method, params ) );
	connect( this, SIGNAL( dataReady( QByteArray ) ), SLOT(onDataReady( QByteArray ) ) );
	deferredStart();
}

void XmlRpcClient::onDataReady( const QByteArray &data )
{
	m_rawData = data;
	QString err;
	qDebug() << QString(data);
	QVariant response  = fromXmlRpcResponse( data, err );
	// TODO fault
	//m_error = err;
	emit dataReady( response, err );
}

